home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 June: Reference Library / Dev.CD Jun 94.toast / Periodicals / develop / ** Special Preview ** / QuickDraw GX Aware Sample ƒ / Simple Sample GX ƒ / Simple Sample.h < prev   
Encoding:
C/C++ Source or Header  |  1994-04-15  |  7.2 KB  |  213 lines  |  [TEXT/KAHL]

  1. /*********************************************************************
  2.  
  3.     Simple Sample.h
  4.     
  5.     This is the header file for the QuickDraw GX aware sample,
  6.     "Simple Sample GX."
  7.     
  8.     Additional info can be found in the related develop #19 article,
  9.     "Adding QuickDraw GX Printing to QuickDraw Applications."
  10.  
  11.     Dave Hersey, Apple Developer Technical Support.
  12.     
  13.     ——————— Edit Trail ———————
  14.     
  15.     spawned:                                        1/22/94  - dmh
  16.     cleaned up for 2nd draft of develop article:    3/10/94  - dmh
  17.     cleaned up for final:                            4/14/94  - dmh
  18.     
  19. *********************************************************************/
  20.  
  21. #include <stdio.h>                            // Regular interface files.
  22. #include <AppleEvents.h>
  23. #include <Desk.h>
  24. #include <Events.h>
  25. #include <Files.h>
  26. #include <Fonts.h>
  27. #include <GestaltEqu.h>
  28. #include <Memory.h>
  29. #include <Packages.h>
  30. #include <Quickdraw.h>
  31. #include <Resources.h>
  32. #include <StandardFile.h>
  33. #include <ToolUtils.h>
  34. #include <Types.h>
  35. #include <Windows.h>
  36.  
  37. #include <graphics routines.h>                // QuickDraw GX interface files.
  38. #include <graphics toolbox.h>
  39. #include <GXExceptions.h>
  40. #include <PrintingManager.h>
  41. #include <PrintingMessages.h>
  42.  
  43. #define    kOSEvent                    app4Evt    /* Event used by MultiFinder                    */
  44. #define    kSuspendResumeMessage        1        /* High byte of suspend/resume event message    */
  45. #define    kResumeMask                    1        /* Bit of message field for resume vs. suspend    */
  46.  
  47. #define        r_About                128            /* Our app's "About…" alert ID.                    */
  48. #define        r_BadConfig            130            /* Our app's "Bad configuration…" alert ID.        */
  49. #define        r_documentPict        128            /* Our PICT's resource ID.                        */
  50. #define        r_documentBitmap    128            /* Our ICON's resource ID.                        */
  51.  
  52. #define        kMyDocCreator        'SSam'        /* Our app's creator.                            */
  53. #define        kMyDocType            'aDoc'        /* Our document file type.                        */
  54. #define        kMyPageCountType    'Pgs?'        /* Our page count resource type.                */
  55. #define        kMyPageCountID        2000        /* Our page count resource ID.                    */
  56. #define        kMyPrintRecType        'THPR'        /* Our print record resource type.                */
  57. #define        kMyPrintRecID        1000        /* Our print record resource ID.                */
  58. #define        kMyJobType            'FJOB'        /* Our gxJob resource type.                        */
  59. #define        kMyJobID            1000        /* Our gxJob resource ID.                        */
  60. #define        kMyFormatInfoType    'FLST'        /* Our format list collection item tag.            */
  61. #define        kMyFormatInfoTagID    1000        /* Our format list collection item ID.            */
  62.  
  63. #define        kGraphicsHeapSize    ((long) 300 * 1024)
  64. #define        kDefaultTitle        ((char *) "\pUntitled Document")
  65.  
  66. // Various PicComments:
  67.  
  68. #define        PostScriptBegin        190
  69. #define        PostScriptEnd        191
  70. #define        PostScriptHandle    192
  71.  
  72.  
  73. /*
  74.     MyDocumentRec - This structure contains information that we store
  75.     about each document we open or create.  We store a handle to one
  76.     of these beasties in each window's refCon field.  Note that the
  77.     MyDocumentRec data type in this example is simplified to handle a
  78.     maximum of 20 pages.
  79. */
  80.  
  81. #define kMaxPages    20
  82.  
  83. typedef struct MyDocumentRec {
  84.         THPrint            documentPrintHdl;            // Print Record bound to this document.
  85.         gxJob            documentJob;                // Job bound to this document.
  86.         gxFormat        pageFormat[kMaxPages];        // format for each page.  If nil, we use
  87.                                                     // the job format.
  88.  
  89.         long            numPages;                    // Number of pages in this document.
  90.         long            curPage;                    // The current page that we're looking at.
  91.         FSSpec            documentFSSpec;                // The file specification for this document.
  92.         Str31            documentTitle;                // The title of this document (such
  93.                                                     // as "Untitled").
  94.         WindowPtr        documentWindow;                // The window for this document.
  95. } MyDocumentRec, *MyDocumentPtr;
  96.  
  97.  
  98. typedef struct MySpoolDataRec {
  99.         gxRectangle        pageArea;                    // Page rectangle.
  100.         gxViewPort        printViewPort;                // ViewPort we're printing with.
  101. } MySpoolDataRec, *MySpoolDataPtr;
  102.  
  103.  
  104. // globals from main.c:
  105.  
  106. extern short                 gAppResRefNum;
  107. extern Rect                 gWindowRect;
  108. extern Boolean                gQuitAfterPrinting, gQuitting, gSystemSevenIsPresent;
  109. extern Boolean                gGXIsPresent, gInPrintDialog;
  110. extern long                    gSleep;
  111. extern gxGraphicsClient        gClient;
  112.  
  113.                     //  Prototypes: //
  114.  
  115. // main.c:
  116.  
  117. void            MyInitialize(void);
  118. void            MyCheckConfig(void);
  119. void            MyInitGXIfPresent(void);
  120. void            MyCleanUpGXIfPresent(void);
  121. OSErr            MyPrintingEventOverride(EventRecord *anEvent, Boolean filterEvent);
  122. void            main(void);
  123.  
  124. // events.c
  125.  
  126. void            MyEventLoop(void);
  127. void            MyDoEvent(EventRecord *theEvent);
  128. void            MyDoAEInstallation(void);
  129. pascal OSErr    MyHandleOAPP(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  130. pascal OSErr    MyHandleQUIT(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  131. pascal OSErr    MyHandleODOC(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  132. pascal OSErr    MyHandlePDOC(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  133. OSErr            MyCheckAEParams(AppleEvent *theAppleEvent);
  134.  
  135. // file.c
  136.  
  137. OSErr            MyLoadDocument(MyDocumentPtr whichDocument);
  138. OSErr            MyFSLoadDocument(MyDocumentPtr destDocument, FSSpec *docFSSpec, Boolean forPrinting);
  139. Boolean            MyIsWindowAlreadyOpen(FSSpec *whichFSSpec);
  140. OSErr            MySaveDocument(MyDocumentPtr myDocument, Boolean doingSaveAs);
  141. OSErr            MySavePageCount(MyDocumentPtr whichDocument, short resRefNum);
  142. long            MyLoadPageCount(short resRefNum);
  143. OSErr            MySaveFormatRefs(MyDocumentPtr whichDocument);
  144. OSErr            MyCreateFormatIndexList(MyDocumentPtr whichDocument, Handle *theFormatIdxList);
  145. OSErr            MyAdjustFormats(MyDocumentPtr whichDocument);
  146. OSErr            MySavePrintInfo(MyDocumentPtr whichDocument, short resRefNum);
  147. OSErr            MyLoadPrintInfo(MyDocumentPtr whichDocument, short resRefNum);
  148.  
  149. // menus & windows.c:
  150.  
  151. OSErr            MyCreateDocument(char *title, MyDocumentPtr *createdDocument);
  152. void            MyDisposeDocument(MyDocumentPtr whichDocument);
  153. OSErr            MyInsertPage(MyDocumentPtr whichDocument, long *whichPage);
  154. void            MyDisposePage(MyDocumentPtr whichDocument, long whichPage);
  155. void            MyUpdateWindow(WindowPtr whichWindow);
  156. void            MyDrawContents(WindowPtr whichWindow);
  157. void            MyDrawPicComments(void);
  158. void            MySendPostScript(Str255 thePostScript);
  159. void            MyAdjustMenus(void);
  160. void            MyAdjustMenusForPrintDialogs(Boolean dialogGoingUp);
  161. void            MyDoMenuCommand(long menuResult);
  162. void            MyConvertMenuItem(short *menuID, short *menuItem);
  163. MyDocumentPtr    MyGetDocPtr(WindowPtr whichWindow);
  164.  
  165. // printing.c:
  166.  
  167. OSErr            MyPrintDocument(MyDocumentPtr whichDocument);
  168. OSErr            MyPrintOneCopy(MyDocumentPtr whichDocument);
  169. OSErr            MyQDPrintLoop(MyDocumentPtr whichDocument);
  170. OSErr            MyGXPrintLoop(MyDocumentPtr whichDocument);
  171. OSErr            MyPrintAShape(gxShape currentShape, long refCon);
  172. Boolean            MyDoPageSetup(MyDocumentPtr whichDocument);
  173. Boolean            MyDoCustomPageSetup(MyDocumentPtr whichDocument);
  174. void            MyRepaginateDoc(MyDocumentPtr whichDocument);
  175. OSErr            MyReplaceCollectionItem(void *newData, long collectSize,
  176.                                         OSType collectType, long collectID,
  177.                                         Collection whichCollection,
  178.                                         Ptr *oldData, long *oldDataSize);
  179.  
  180. // resource & menu item equates:
  181.  
  182. #define rMenuBar        128
  183. #define mApple            128
  184. #define     iAbout                1
  185.  
  186. #define mFile            129
  187. #define     iNew                1
  188. #define     iOpen                2
  189. #define     iClose                3
  190. #define     iSave                4
  191. #define     iSaveAs            5
  192. #define     iPageSetup            7
  193. #define     iCustomPageSetup    8
  194. #define     iPrint                9
  195. #define     iPrintOneCopy        10
  196. #define     iQuit                   12
  197.  
  198. #define mEdit            130
  199. #define     iUndo                1
  200. #define     iCut                3
  201. #define     iCopy                4
  202. #define     iPaste                5
  203. #define     iClear                6
  204.  
  205. #define mDocument        131
  206. #define     iInsertPage        1
  207. #define     iDeletePage        2
  208. #define     iAheadPage            4
  209. #define     iBackPage            5
  210.  
  211.  
  212.  
  213.